package com.gxx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gxx.entity.Good1;
import com.gxx.entity.User1;
import com.gxx.entity.Usergood;
import com.gxx.mapper.Good1Mapper;
import com.gxx.mapper.User1Mapper;
import com.gxx.mapper.UsergoodMapper;
import com.gxx.service.User1Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gxx
 * @since 2022-12-04
 */
@Service
public class User1ServiceImpl extends ServiceImpl<User1Mapper, User1> implements User1Service {
@Autowired
private UsergoodMapper ugm;
@Autowired
private Good1Mapper gm;
    /**
     * 给我用户id  返回商品信息
     *
     * @param uid
     * @return
     */
    @Override
    public List<Good1> getGoodByUid(int uid) {
        QueryWrapper<Usergood> wrapper=new QueryWrapper<>();
        wrapper.eq("uid",uid);
        List<Usergood> ugoods=ugm.selectList(wrapper);
        List<Good1> good1s=new ArrayList<>();//某个用户的商品信息
        for (Usergood usergood:ugoods) {
            int gid=usergood.getGid();//去除关系表gid
            Good1 good1 = gm.selectById(gid);
            good1s.add(good1);
        }
        return good1s;
    }
}
